package homework09;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;

public class homework005 {
	public static void main(String[] args) throws Exception {
	
		ArrayList<Student1> list1 = new ArrayList<>();
		ArrayList<Student1> list2 = new ArrayList<>();
		BufferedReader br = new BufferedReader(new FileReader("names05.txt"));
		int count=0;
		String line;
		while((line=br.readLine())!=null){
			String[] split = line.split("-");
			Student1 s = new Student1(split[0],split[1],Integer.parseInt(split[2]),Integer.parseInt(split[3]));
			if(s.getNumber()==0){
				list1.add(s);
			}else{
				list2.add(s);
			}
		}
		br.close();
		if(list1.size()==0){
			Collections.shuffle(list2);
			System.out.println(list2.get(0).toString());
			BufferedWriter bw = new BufferedWriter(new FileWriter("names05.txt"));
			for(Student1 s:list2){
				if(s==list2.get(0)){
					bw.write(s.toString()+"-"+1);
					bw.newLine();
				}else{
					bw.write(s.toString()+"-"+0);
					bw.newLine();
				}
			}
			bw.close();
		}else{
			ArrayList<Student1> list3 = new ArrayList<>();
			Collections.shuffle(list1);
			System.out.println(list1.get(0).toString());
			list1.get(0).setNumber(1);
			list2.add(list1.get(0));
			list1.remove(0);
			list3.addAll(list1);
			list3.addAll(list2);
			BufferedWriter bw = new BufferedWriter(new FileWriter("names05.txt"));
			for(Student1 s:list3){
				bw.write(s.toString()+"-"+s.getNumber());
				bw.newLine();
			}
			bw.close();
		}

	}
}
